/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package SolvedProblems;

//10300 
//import acmproblem.Temporary.*;
import java.io.File;
import java.util.Scanner;

/**
 *
 * @author Power User
 */
public class EcologicalPremium {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        new EcologicalPremium().begin();
    }

    public void begin(){
        try{
            //File f = new File("input.txt");
            //Scanner scan = new Scanner(f);
            Scanner scan = new Scanner(System.in);
            int testCaseT = scan.nextInt();
            for(; testCaseT > 0; testCaseT--){
                int testCaseI = scan.nextInt();
                int sum = 0;
                for(; testCaseI > 0; testCaseI--){
                    int area = scan.nextInt();
                    int animal = scan.nextInt();
                    int envFrnd = scan.nextInt();
                    sum = sum + (area ) * envFrnd;
                }//end for
                System.out.println(sum);
            }//end for

        }catch(Exception ex){

        }//end of try catch
    }//end of begin

}//end of class
